package com.lly.schedule.controller;


import com.lly.schedule.common.Result;
import com.lly.schedule.pojo.SysSchedule;
import com.lly.schedule.serice.SysScheduleService;
import com.lly.schedule.serice.impl.SysScheduleServiceImpl;
import com.lly.schedule.util.WebUtil;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@WebServlet("/syschdeule/*")
public class SysScheduleController extends BaseController {
    SysScheduleService sysScheduleService=new SysScheduleServiceImpl();

    protected void findAll(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        String username = req.getParameter("uid");
        int uid = Integer.parseInt(username);
        List<SysSchedule> itemList=sysScheduleService.findAll(uid);
        Map map=new HashMap();
        map.put("itemList",itemList);
        System.out.println(map);
        Result result= Result.ok(map);
        WebUtil.writeJson(resp,result);
    }

    protected void add(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        int uid = Integer.parseInt(req.getParameter("uid"));
        sysScheduleService.add(uid);
        WebUtil.writeJson(resp,Result.ok(null));
    }

    protected void update(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        SysSchedule sysSchedule = WebUtil.readJson(req, SysSchedule.class);
        sysScheduleService.update(sysSchedule);
        WebUtil.writeJson(resp,Result.ok(null));
    }
    protected void remove(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        int sid = Integer.parseInt(req.getParameter("sid"));
        sysScheduleService.remove(sid);
        WebUtil.writeJson(resp,Result.ok(null));
    }
}
